home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Fixation 1.3 / MyMacTCP.h < prev    next >
Text File  |  1995-01-07  |  28KB  |  1,055 lines

  1. /*
  2.      File:        MacTCP.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.                  With additions and corrections by Eric Scouten, Friday, December 2, 1994.
  9.  
  10.      Bugs?:        If you find a problem with this file, send the file and version
  11.                  information (from above) and the problem description to:
  12.  
  13.                      Internet:    apple.bugs@applelink.apple.com
  14.                      AppleLink:    APPLE.BUGS
  15.                      
  16.      TCPSendPB error fixed by jln, 1/7/95.
  17.  
  18. */
  19.  
  20. #ifndef __MACTCP__
  21. #define __MACTCP__
  22.  
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. /*    #include <ConditionalMacros.h>                                */
  28.  
  29. #ifndef __APPLETALK__
  30. #include <AppleTalk.h>
  31. #endif
  32. /*    #include <OSUtils.h>                                        */
  33. /*        #include <MixedMode.h>                                    */
  34. /*        #include <Memory.h>                                        */
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39.  
  40. #if GENERATINGPOWERPC
  41. #pragma options align=mac68k
  42. #endif
  43.  
  44. #ifdef __CFM68K__
  45. #pragma lib_export on
  46. #endif
  47.  
  48.  
  49. enum {
  50.     inProgress                    = 1,                            /* I/O in progress */
  51.     ipBadLapErr                    = -23000,                        /* bad network configuration */
  52.     ipBadCnfgErr                = -23001,                        /* bad IP configuration error */
  53.     ipNoCnfgErr                    = -23002,                        /* missing IP or LAP configuration error */
  54.     ipLoadErr                    = -23003,                        /* error in MacTCP load */
  55.     ipBadAddr                    = -23004,                        /* error in getting address */
  56.     connectionClosing            = -23005,                        /* connection is closing */
  57.     invalidLength                = -23006,
  58.     connectionExists            = -23007,                        /* request conflicts with existing connection */
  59.     connectionDoesntExist        = -23008,                        /* connection does not exist */
  60.     insufficientResources        = -23009,                        /* insufficient resources to perform request */
  61.     invalidStreamPtr            = -23010,
  62.     streamAlreadyOpen            = -23011,
  63.     connectionTerminated        = -23012,
  64.     invalidBufPtr                = -23013,
  65.     invalidRDS                    = -23014,
  66.     invalidWDS                    = -23014,
  67.     openFailed                    = -23015,
  68.     commandTimeout                = -23016,
  69.     duplicateSocket                = -23017
  70. };
  71.  
  72. /* Error codes from internal IP functions */
  73. enum {
  74.     ipDontFragErr                = -23032,                        /* Packet too large to send w/o fragmenting */
  75.     ipDestDeadErr                = -23033,                        /* destination not responding */
  76.     icmpEchoTimeoutErr            = -23035,                        /* ICMP echo timed-out */
  77.     ipNoFragMemErr                = -23036,                        /* no memory to send fragmented pkt */
  78.     ipRouteErr                    = -23037,                        /* can't route packet off-net */
  79.     nameSyntaxErr                = -23041,
  80.     cacheFault                    = -23042,
  81.     noResultProc                = -23043,
  82.     noNameServer                = -23044,
  83.     authNameErr                    = -23045,
  84.     noAnsErr                    = -23046,
  85.     dnrErr                        = -23047,
  86.     outOfMemory                    = -23048
  87. };
  88.  
  89. enum {
  90.     BYTES_16WORD                = 2,                            /* bytes per = 16, bit ip word */
  91.     BYTES_32WORD                = 4,                            /* bytes per = 32, bit ip word */
  92.     BYTES_64WORD                = 8                                /* bytes per = 64, bit ip word */
  93. };
  94.  
  95. typedef unsigned char b_8;
  96.  
  97. typedef unsigned short b_16;
  98.  
  99. typedef unsigned long b_32;
  100.  
  101. typedef b_32 ip_addr;
  102.  
  103. struct ip_addrbytes {
  104.         union {
  105.             b_32                            addr;
  106.             char                            byte[4];
  107.         }                            a;
  108. };
  109. typedef struct ip_addrbytes ip_addrbytes;
  110.  
  111. struct wdsEntry {
  112.     unsigned short                    length;                        /* length of buffer */
  113.     char                            *ptr;                        /* pointer to buffer */
  114. };
  115. typedef struct wdsEntry wdsEntry;
  116.  
  117. struct rdsEntry {
  118.     unsigned short                    length;                        /* length of buffer */
  119.     char                            *ptr;                        /* pointer to buffer */
  120. };
  121. typedef struct rdsEntry rdsEntry;
  122.  
  123. typedef unsigned long BufferPtr;
  124.  
  125. typedef unsigned long StreamPtr;
  126.  
  127.  
  128. enum {
  129.     netUnreach                    = 0,
  130.     hostUnreach                    = 1,
  131.     protocolUnreach                = 2,
  132.     portUnreach                    = 3,
  133.     fragReqd                    = 4,
  134.     sourceRouteFailed            = 5,
  135.     timeExceeded                = 6,
  136.     parmProblem                    = 7,
  137.     missingOption                = 8
  138. };
  139.  
  140. typedef unsigned short ICMPMsgType;
  141.  
  142. typedef b_16 ip_port;
  143.  
  144. struct ICMPReport {
  145.     StreamPtr                        streamPtr;
  146.     ip_addr                            localHost;
  147.     ip_port                            localPort;
  148.     ip_addr                            remoteHost;
  149.     ip_port                            remotePort;
  150.     short                            reportType;
  151.     unsigned short                    optionalAddlInfo;
  152.     unsigned long                    optionalAddlInfoPtr;
  153. };
  154. typedef struct ICMPReport ICMPReport;
  155.  
  156. typedef OSErr (*OSErrProcPtr)();
  157.  
  158. #if GENERATINGCFM
  159. typedef UniversalProcPtr OSErrUPP;
  160. #else
  161. typedef OSErrProcPtr OSErrUPP;
  162. #endif
  163.  
  164. enum {
  165.     uppOSErrProcInfo = kCStackBased
  166.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  167. };
  168.  
  169. #if GENERATINGCFM
  170. #define NewOSErrProc(userRoutine)        \
  171.         (OSErrUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppOSErrProcInfo, GetCurrentArchitecture())
  172. #else
  173. #define NewOSErrProc(userRoutine)        \
  174.         ((OSErrUPP) (userRoutine))
  175. #endif
  176.  
  177. #if GENERATINGCFM
  178. #define CallOSErrProc(userRoutine)        \
  179.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppOSErrProcInfo)
  180. #else
  181. #define CallOSErrProc(userRoutine)        \
  182.         (*(userRoutine))()
  183. #endif
  184.  
  185. typedef Ptr (*PtrProcPtr)();
  186.  
  187. #if GENERATINGCFM
  188. typedef UniversalProcPtr PtrUPP;
  189. #else
  190. typedef PtrProcPtr PtrUPP;
  191. #endif
  192.  
  193. enum {
  194.     uppPtrProcInfo = kCStackBased
  195.          | RESULT_SIZE(SIZE_CODE(sizeof(Ptr)))
  196. };
  197.  
  198. #if GENERATINGCFM
  199. #define NewPtrProc(userRoutine)        \
  200.         (PtrUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppPtrProcInfo, GetCurrentArchitecture())
  201. #else
  202. #define NewPtrProc(userRoutine)        \
  203.         ((PtrUPP) (userRoutine))
  204. #endif
  205.  
  206. #if GENERATINGCFM
  207. #define CallPtrProc(userRoutine)        \
  208.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppPtrProcInfo)
  209. #else
  210. #define CallPtrProc(userRoutine)        \
  211.         (*(userRoutine))()
  212. #endif
  213.  
  214. typedef Boolean (*BooleanProcPtr)();
  215.  
  216. #if GENERATINGCFM
  217. typedef UniversalProcPtr BooleanUPP;
  218. #else
  219. typedef BooleanProcPtr BooleanUPP;
  220. #endif
  221.  
  222. enum {
  223.     uppBooleanProcInfo = kCStackBased
  224.          | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  225. };
  226.  
  227. #if GENERATINGCFM
  228. #define NewBooleanProc(userRoutine)        \
  229.         (BooleanUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppBooleanProcInfo, GetCurrentArchitecture())
  230. #else
  231. #define NewBooleanProc(userRoutine)        \
  232.         ((BooleanUPP) (userRoutine))
  233. #endif
  234.  
  235. #if GENERATINGCFM
  236. #define CallBooleanProc(userRoutine)        \
  237.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppBooleanProcInfo)
  238. #else
  239. #define CallBooleanProc(userRoutine)        \
  240.         (*(userRoutine))()
  241. #endif
  242.  
  243.  
  244. enum {
  245.     NUM_ALT_ADDRS                = 4
  246. };
  247.  
  248. struct hostInfo {
  249.     long                            rtnCode;
  250.     char                            cname[255];
  251.     UInt8                            filler;                        /* Filler for proper byte alignment     */
  252.     unsigned long                    addr[NUM_ALT_ADDRS];
  253. };
  254. typedef struct hostInfo hostInfo;
  255.  
  256.  
  257. enum {
  258.     A                            = 1,
  259.     NS                            = 2,
  260.     CNAME                        = 5,
  261.     HINFO                        = 13,
  262.     MX                            = 15
  263. };
  264.  
  265. typedef unsigned short AddrClasses;
  266.  
  267. struct HInfoRec {
  268.     char                            cpuType[30];
  269.     char                            osType[30];
  270. };
  271. typedef struct HInfoRec HInfoRec;
  272.  
  273. struct MXRec {
  274.     unsigned short                    preference;
  275.     char                            exchange[255];
  276. };
  277. typedef struct MXRec MXRec;
  278.  
  279. struct returnRec {
  280.     long                            rtnCode;
  281.     char                            cname[255];
  282.     UInt8                            filler;                        /* Filler for proper byte alignment     */
  283.         union {
  284.             unsigned long                    addr[NUM_ALT_ADDRS];
  285.             struct HInfoRec                    hinfo;
  286.             struct MXRec                    mx;
  287.         }                            rdata;
  288. };
  289. struct cacheEntryRecord {
  290.     char                            *cname;
  291.     unsigned short                    ctype;
  292.     unsigned short                    cacheClass;
  293.     unsigned long                    ttl;
  294.         union {
  295.             char                            *name;
  296.             ip_addr                            addr;
  297.         }                            rdata;
  298. };
  299. typedef struct returnRec returnRec;
  300.  
  301. typedef struct cacheEntryRecord cacheEntryRecord;
  302.  
  303. typedef pascal void (*EnumResultProcPtr)(struct cacheEntryRecord *cacheEntryRecordPtr, char *userDataPtr);
  304.  
  305. #if GENERATINGCFM
  306. typedef UniversalProcPtr EnumResultUPP;
  307. #else
  308. typedef EnumResultProcPtr EnumResultUPP;
  309. #endif
  310.  
  311. enum {
  312.     uppEnumResultProcInfo = kPascalStackBased
  313.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct cacheEntryRecord*)))
  314.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*)))
  315. };
  316.  
  317. #if GENERATINGCFM
  318. #define NewEnumResultProc(userRoutine)        \
  319.         (EnumResultUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppEnumResultProcInfo, GetCurrentArchitecture())
  320. #else
  321. #define NewEnumResultProc(userRoutine)        \
  322.         ((EnumResultUPP) (userRoutine))
  323. #endif
  324.  
  325. #if GENERATINGCFM
  326. #define CallEnumResultProc(userRoutine, cacheEntryRecordPtr, userDataPtr)        \
  327.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppEnumResultProcInfo, (cacheEntryRecordPtr), (userDataPtr))
  328. #else
  329. #define CallEnumResultProc(userRoutine, cacheEntryRecordPtr, userDataPtr)        \
  330.         (*(userRoutine))((cacheEntryRecordPtr), (userDataPtr))
  331. #endif
  332.  
  333. typedef pascal void (*ResultProcPtr)(struct hostInfo *hostInfoPtr, char *userDataPtr);
  334.  
  335. #if GENERATINGCFM
  336. typedef UniversalProcPtr ResultUPP;
  337. #else
  338. typedef ResultProcPtr ResultUPP;
  339. #endif
  340.  
  341. enum {
  342.     uppResultProcInfo = kPascalStackBased
  343.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct hostInfo*)))
  344.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*)))
  345. };
  346.  
  347. #if GENERATINGCFM
  348. #define NewResultProc(userRoutine)        \
  349.         (ResultUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppResultProcInfo, GetCurrentArchitecture())
  350. #else
  351. #define NewResultProc(userRoutine)        \
  352.         ((ResultUPP) (userRoutine))
  353. #endif
  354.  
  355. #if GENERATINGCFM
  356. #define CallResultProc(userRoutine, hostInfoPtr, userDataPtr)        \
  357.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppResultProcInfo, (hostInfoPtr), (userDataPtr))
  358. #else
  359. #define CallResultProc(userRoutine, hostInfoPtr, userDataPtr)        \
  360.         (*(userRoutine))((hostInfoPtr), (userDataPtr))
  361. #endif
  362.  
  363. typedef pascal void (*Result2ProcPtr)(struct returnRec *returnRecPtr, char *userDataPtr);
  364.  
  365. #if GENERATINGCFM
  366. typedef UniversalProcPtr Result2UPP;
  367. #else
  368. typedef Result2ProcPtr Result2UPP;
  369. #endif
  370.  
  371. enum {
  372.     uppResult2ProcInfo = kPascalStackBased
  373.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct returnRec*)))
  374.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*)))
  375. };
  376.  
  377. #if GENERATINGCFM
  378. #define NewResult2Proc(userRoutine)        \
  379.         (Result2UPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppResult2ProcInfo, GetCurrentArchitecture())
  380. #else
  381. #define NewResult2Proc(userRoutine)        \
  382.         ((Result2UPP) (userRoutine))
  383. #endif
  384.  
  385. #if GENERATINGCFM
  386. #define CallResult2Proc(userRoutine, returnRecPtr, userDataPtr)        \
  387.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppResult2ProcInfo, (returnRecPtr), (userDataPtr))
  388. #else
  389. #define CallResult2Proc(userRoutine, returnRecPtr, userDataPtr)        \
  390.         (*(userRoutine))((returnRecPtr), (userDataPtr))
  391. #endif
  392.  
  393. #if OLDROUTINENAMES                    // •• ES addition
  394.     #define ResultProc2ProcPtr Result2ProcPtr
  395.     #define uppResultProc2ProcInfo uppResult2ProcInfo
  396.     #define ResultProc2UPP Result2UPP
  397.     #define CallResultProc2Proc CallResult2Proc
  398.     #define NewResultProc2Proc NewResult2Proc
  399. #endif
  400.  
  401. extern pascal OSErr OpenResolver(char *fileName);
  402. extern pascal OSErr StrToAddr(char *hostName, struct hostInfo *hostInfoPtr, ResultUPP ResultProc, char *userDataPtr);
  403. extern pascal OSErr AddrToStr(unsigned long addr, char *addrStr);
  404. extern pascal OSErr EnumCache(EnumResultUPP enumResultProc, char *userDataPtr);
  405. extern pascal OSErr AddrToName(ip_addr addr, struct hostInfo *hostInfoPtr, ResultUPP ResultProc, char *userDataPtr);
  406. extern pascal OSErr HInfo(char *hostName, struct returnRec *returnRecPtr, Result2UPP resultProc, char *userDataPtr);
  407. extern pascal OSErr MXInfo(char *hostName, struct returnRec *returnRecPtr, Result2UPP resultProc, char *userDataPtr);
  408. extern pascal OSErr CloseResolver(void);
  409. /* csCode to get our IP address */
  410.  
  411. enum {
  412.     ipctlGetAddr                = 15
  413. };
  414.  
  415. struct GetAddrParamBlock {
  416.     struct QElem                    *qLink;
  417.     short                            qType;
  418.     short                            ioTrap;
  419.     Ptr                                ioCmdAddr;
  420.     UniversalProcPtr                ioCompletion;
  421.     OSErr                            ioResult;
  422.     StringPtr                        ioNamePtr;
  423.     short                            ioVRefNum;
  424.     short                            ioCRefNum;
  425.     short                            csCode;                        /* standard I/O header */
  426.     ip_addr                            ourAddress;                    /* our IP address */
  427.     long                            ourNetMask;                    /* our IP net mask */
  428. };
  429. typedef struct GetAddrParamBlock GetAddrParamBlock;
  430.  
  431. /* control codes */
  432.  
  433. enum {
  434.     ipctlEchoICMP                = 17,                            /* send icmp echo */
  435.     ipctlLAPStats                = 19                            /* get lap stats */
  436. };
  437.  
  438. struct ICMPParamBlock {
  439.     struct QElem                    *qLink;
  440.     short                            qType;
  441.     short                            ioTrap;
  442.     Ptr                                ioCmdAddr;
  443.     UniversalProcPtr                ioCompletion;
  444.     OSErr                            ioResult;
  445.     StringPtr                        ioNamePtr;
  446.     short                            ioVRefNum;
  447.     short                            ioCRefNum;
  448.     short                            csCode;                        /* standard I/O header */
  449.     short                            params[11];
  450.         struct {
  451.             unsigned long                    echoRequestOut;        /* time in ticks of when the echo request went out */
  452.             unsigned long                    echoReplyIn;        /* time in ticks of when the reply was received */
  453.             struct rdsEntry                    echoedData;            /* data received in responce */
  454.             Ptr                                options;
  455.             unsigned long                    userDataPtr;
  456.         }                            icmpEchoInfo;
  457. };
  458.  
  459. enum {
  460.     NBP_TABLE_SIZE                = 20,                            /* number of NBP table entries */
  461.     NBP_MAX_NAME_SIZE            = 16 + 10 + 2
  462. };
  463.  
  464. struct nbp_entry {
  465.     ip_addr                            ip_address;                    /* IP address */
  466.     AddrBlock                        at_address;                    /* matching AppleTalk address */
  467.     Boolean                            gateway;                    /* TRUE if entry for a gateway */
  468.     Boolean                            valid;                        /* TRUE if LAP address is valid */
  469.     Boolean                            probing;                    /* TRUE if NBP lookup pending */
  470.     UInt8                            afiller;                    /* Filler for proper byte alignment     */
  471.     long                            age;                        /* ticks since cache entry verified */
  472.     long                            access;                        /* ticks since last access */
  473.     char                            filler[116];                /* for internal use only !!! */
  474. };
  475. /* number of ARP table entries */
  476.  
  477. enum {
  478.     ARP_TABLE_SIZE                = 20
  479. };
  480.  
  481. struct Enet_addr {
  482.     b_16                            en_hi;
  483.     b_32                            en_lo;
  484. };
  485. typedef struct Enet_addr Enet_addr;
  486.  
  487. struct arp_entry {
  488.     short                            age;                        /* cache aging field */
  489.     b_16                            protocol;                    /* Protocol type */
  490.     ip_addr                            ip_address;                    /* IP address */
  491.     Enet_addr                        en_address;                    /* matching Ethernet address */
  492. };
  493. typedef struct arp_entry arp_entry;
  494.  
  495. /* Command codes */
  496.  
  497. enum {
  498.     TCPCreate                    = 30,
  499.     TCPPassiveOpen                = 31,
  500.     TCPActiveOpen                = 32,
  501.     TCPSend                        = 34,
  502.     TCPNoCopyRcv                = 35,
  503.     TCPRcvBfrReturn                = 36,
  504.     TCPRcv                        = 37,
  505.     TCPClose                    = 38,
  506.     TCPAbort                    = 39,
  507.     TCPStatus                    = 40,
  508.     TCPExtendedStat                = 41,
  509.     TCPRelease                    = 42,
  510.     TCPGlobalInfo                = 43,
  511.     TCPCtlMax                    = 49
  512. };
  513.  
  514. typedef void (*ICMPEchoNotifyProcPtr)(struct ICMPParamBlock *iopb);
  515.  
  516. #if GENERATINGCFM
  517. typedef UniversalProcPtr ICMPEchoNotifyUPP;
  518. #else
  519. typedef ICMPEchoNotifyProcPtr ICMPEchoNotifyUPP;
  520. #endif
  521.  
  522. enum {
  523.     uppICMPEchoNotifyProcInfo = kCStackBased
  524.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct ICMPParamBlock*)))
  525. };
  526.  
  527. #if GENERATINGCFM
  528. #define NewICMPEchoNotifyProc(userRoutine)        \
  529.         (ICMPEchoNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppICMPEchoNotifyProcInfo, GetCurrentArchitecture())
  530. #else
  531. #define NewICMPEchoNotifyProc(userRoutine)        \
  532.         ((ICMPEchoNotifyUPP) (userRoutine))
  533. #endif
  534.  
  535. #if GENERATINGCFM
  536. #define CallICMPEchoNotifyProc(userRoutine, iopb)        \
  537.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppICMPEchoNotifyProcInfo, (iopb))
  538. #else
  539. #define CallICMPEchoNotifyProc(userRoutine, iopb)        \
  540.         (*(userRoutine))((iopb))
  541. #endif
  542.  
  543. struct IPParamBlock {
  544.     struct QElem                    *qLink;
  545.     short                            qType;
  546.     short                            ioTrap;
  547.     Ptr                                ioCmdAddr;
  548.     UniversalProcPtr                ioCompletion;
  549.     OSErr                            ioResult;
  550.     StringPtr                        ioNamePtr;
  551.     short                            ioVRefNum;
  552.     short                            ioCRefNum;
  553.     short                            csCode;                        /* standard I/O header */
  554.         union {
  555.                 struct {
  556.                     ip_addr                            dest;        /* echo to IP address */
  557.                     wdsEntry                        data;
  558.                     short                            timeout;
  559.                     Ptr                                options;
  560.                     unsigned short                    optLength;
  561.                     ICMPEchoNotifyUPP                icmpCompletion;
  562.                     unsigned long                    userDataPtr;
  563.                 }                            IPEchoPB;
  564.                 struct {
  565.                     struct LAPStats                    *lapStatsPtr;
  566.                 }                            LAPStatsPB;
  567.         }                            csParam;
  568. };
  569. struct LAPStats {
  570.     short                            ifType;
  571.     char                            *ifString;
  572.     short                            ifMaxMTU;
  573.     long                            ifSpeed;
  574.     short                            ifPhyAddrLength;
  575.     char                            *ifPhysicalAddress;
  576.         union {
  577.             struct arp_entry                *arp_table;
  578.             struct nbp_entry                *nbp_table;
  579.         }                            AddrXlation;
  580.     short                            slotNumber;
  581. };
  582. typedef struct LAPStats LAPStats;
  583.  
  584.  
  585. enum {
  586.     TCPClosing                    = 1,
  587.     TCPULPTimeout                = 2,
  588.     TCPTerminate                = 3,
  589.     TCPDataArrival                = 4,
  590.     TCPUrgent                    = 5,
  591.     TCPICMPReceived                = 6
  592. };
  593.  
  594. typedef unsigned short TCPEventCode;
  595.  
  596.  
  597. enum {
  598.     TCPRemoteAbort                = 2,
  599.     TCPNetworkFailure            = 3,
  600.     TCPSecPrecMismatch            = 4,
  601.     TCPULPTimeoutTerminate        = 5,
  602.     TCPULPAbort                    = 6,
  603.     TCPULPClose                    = 7,
  604.     TCPServiceError                = 8
  605. };
  606.  
  607. typedef unsigned short TCPTerminationReason;
  608.  
  609. typedef pascal void (*TCPNotifyProcPtr)(StreamPtr tcpStream, unsigned short eventCode, Ptr userDataPtr, unsigned short terminReason, struct ICMPReport *icmpMsg);
  610.  
  611. #if GENERATINGCFM
  612. typedef UniversalProcPtr TCPNotifyUPP;
  613. #else
  614. typedef TCPNotifyProcPtr TCPNotifyUPP;
  615. #endif
  616.  
  617. enum {
  618.     uppTCPNotifyProcInfo = kPascalStackBased
  619.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(StreamPtr)))
  620.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned short)))
  621.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Ptr)))
  622.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(unsigned short)))
  623.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(struct ICMPReport*)))
  624. };
  625.  
  626. #if GENERATINGCFM
  627. #define NewTCPNotifyProc(userRoutine)        \
  628.         (TCPNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppTCPNotifyProcInfo, GetCurrentArchitecture())
  629. #else
  630. #define NewTCPNotifyProc(userRoutine)        \
  631.         ((TCPNotifyUPP) (userRoutine))
  632. #endif
  633.  
  634. #if GENERATINGCFM
  635. #define CallTCPNotifyProc(userRoutine, tcpStream, eventCode, userDataPtr, terminReason, icmpMsg)        \
  636.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppTCPNotifyProcInfo, (tcpStream), (eventCode), (userDataPtr), (terminReason), (icmpMsg))
  637. #else
  638. #define CallTCPNotifyProc(userRoutine, tcpStream, eventCode, userDataPtr, terminReason, icmpMsg)        \
  639.         (*(userRoutine))((tcpStream), (eventCode), (userDataPtr), (terminReason), (icmpMsg))
  640. #endif
  641.  
  642. typedef unsigned short tcp_port;
  643.  
  644. #if OLDROUTINENAMES                        // •• ES addition
  645. typedef unsigned char byte;
  646. #endif OLDROUTINENAMES
  647.  
  648.  
  649. /* ValidityFlags */
  650.  
  651. enum {
  652.     timeoutValue                = 0x80,
  653.     timeoutAction                = 0x40,
  654.     typeOfService                = 0x20,
  655.     precedence                    = 0x10
  656. };
  657.  
  658. /* TOSFlags */
  659. enum {
  660.     lowDelay                    = 0x01,
  661.     throughPut                    = 0x02,
  662.     reliability                    = 0x04
  663. };
  664.  
  665. struct TCPCreatePB {
  666.     Ptr                                rcvBuff;
  667.     unsigned long                    rcvBuffLen;
  668.     TCPNotifyUPP                    notifyProc;
  669.     Ptr                                userDataPtr;
  670. };
  671. typedef struct TCPCreatePB TCPCreatePB;
  672.  
  673. struct TCPOpenPB {
  674.     SInt8                            ulpTimeoutValue;
  675.     SInt8                            ulpTimeoutAction;
  676.     SInt8                            validityFlags;
  677.     SInt8                            commandTimeoutValue;
  678.     ip_addr                            remoteHost;
  679.     tcp_port                        remotePort;
  680.     ip_addr                            localHost;
  681.     tcp_port                        localPort;
  682.     SInt8                            tosFlags;
  683.     SInt8                            precedence;
  684.     Boolean                            dontFrag;
  685.     SInt8                            timeToLive;
  686.     SInt8                            security;
  687.     SInt8                            optionCnt;
  688.     SInt8                            options[40];
  689.     Ptr                                userDataPtr;
  690. };
  691. typedef struct TCPOpenPB TCPOpenPB;
  692.  
  693. struct TCPSendPB {
  694.     SInt8                            ulpTimeoutValue;
  695.     SInt8                            ulpTimeoutAction;
  696.     SInt8                            validityFlags;
  697.     Boolean                            pushFlag;
  698.     Boolean                            urgentFlag;
  699.     UInt8                            filler;                        /* Filler for proper byte alignment     */
  700.     Ptr                                wdsPtr;
  701.     unsigned long                    sendFree;
  702.     unsigned short                    sendLength;
  703.     Ptr                                userDataPtr;
  704. };
  705. typedef struct TCPSendPB TCPSendPB;
  706.  
  707. /* for receive and return rcv buff calls */
  708. struct TCPReceivePB {
  709.     SInt8                            commandTimeoutValue;
  710.     SInt8                            filler;
  711.     Boolean                            markFlag;
  712.     Boolean                            urgentFlag;
  713.     Ptr                                rcvBuff;
  714.     unsigned short                    rcvBuffLen;
  715.     Ptr                                rdsPtr;
  716.     unsigned short                    rdsLength;
  717.     unsigned short                    secondTimeStamp;
  718.     Ptr                                userDataPtr;
  719. };
  720. typedef struct TCPReceivePB TCPReceivePB;
  721.  
  722. struct TCPClosePB {
  723.     SInt8                            ulpTimeoutValue;
  724.     SInt8                            ulpTimeoutAction;
  725.     SInt8                            validityFlags;
  726.     UInt8                            filler;                        /* Filler for proper byte alignment     */
  727.     Ptr                                userDataPtr;
  728. };
  729. typedef struct TCPClosePB TCPClosePB;
  730.  
  731. struct HistoBucket {
  732.     unsigned short                    value;
  733.     unsigned long                    counter;
  734. };
  735. typedef struct HistoBucket HistoBucket;
  736.  
  737.  
  738. enum {
  739.     NumOfHistoBuckets            = 7
  740. };
  741.  
  742. struct TCPConnectionStats {
  743.     unsigned long                    dataPktsRcvd;
  744.     unsigned long                    dataPktsSent;
  745.     unsigned long                    dataPktsResent;
  746.     unsigned long                    bytesRcvd;
  747.     unsigned long                    bytesRcvdDup;
  748.     unsigned long                    bytesRcvdPastWindow;
  749.     unsigned long                    bytesSent;
  750.     unsigned long                    bytesResent;
  751.     unsigned short                    numHistoBuckets;
  752.     struct HistoBucket                sentSizeHisto[NumOfHistoBuckets];
  753.     unsigned short                    lastRTT;
  754.     unsigned short                    tmrSRTT;
  755.     unsigned short                    rttVariance;
  756.     unsigned short                    tmrRTO;
  757.     SInt8                            sendTries;
  758.     SInt8                            sourchQuenchRcvd;
  759. };
  760. typedef struct TCPConnectionStats TCPConnectionStats;
  761.  
  762. struct TCPStatusPB {
  763.     SInt8                            ulpTimeoutValue;
  764.     SInt8                            ulpTimeoutAction;
  765.     long                            unused;
  766.     ip_addr                            remoteHost;
  767.     tcp_port                        remotePort;
  768.     ip_addr                            localHost;
  769.     tcp_port                        localPort;
  770.     SInt8                            tosFlags;
  771.     SInt8                            precedence;
  772.     SInt8                            connectionState;
  773.     UInt8                            filler;                        /* Filler for proper byte alignment     */
  774.     unsigned short                    sendWindow;
  775.     unsigned short                    rcvWindow;
  776.     unsigned short                    amtUnackedData;
  777.     unsigned short                    amtUnreadData;
  778.     Ptr                                securityLevelPtr;
  779.     unsigned long                    sendUnacked;
  780.     unsigned long                    sendNext;
  781.     unsigned long                    congestionWindow;
  782.     unsigned long                    rcvNext;
  783.     unsigned long                    srtt;
  784.     unsigned long                    lastRTT;
  785.     unsigned long                    sendMaxSegSize;
  786.     struct TCPConnectionStats        *connStatPtr;
  787.     Ptr                                userDataPtr;
  788. };
  789. typedef struct TCPStatusPB TCPStatusPB;
  790.  
  791. struct TCPAbortPB {
  792.     Ptr                                userDataPtr;
  793. };
  794. typedef struct TCPAbortPB TCPAbortPB;
  795.  
  796. struct TCPParam {
  797.     unsigned long                    tcpRtoA;
  798.     unsigned long                    tcpRtoMin;
  799.     unsigned long                    tcpRtoMax;
  800.     unsigned long                    tcpMaxSegSize;
  801.     unsigned long                    tcpMaxConn;
  802.     unsigned long                    tcpMaxWindow;
  803. };
  804. typedef struct TCPParam TCPParam;
  805.  
  806. struct TCPStats {
  807.     unsigned long                    tcpConnAttempts;
  808.     unsigned long                    tcpConnOpened;
  809.     unsigned long                    tcpConnAccepted;
  810.     unsigned long                    tcpConnClosed;
  811.     unsigned long                    tcpConnAborted;
  812.     unsigned long                    tcpOctetsIn;
  813.     unsigned long                    tcpOctetsOut;
  814.     unsigned long                    tcpOctetsInDup;
  815.     unsigned long                    tcpOctetsRetrans;
  816.     unsigned long                    tcpInputPkts;
  817.     unsigned long                    tcpOutputPkts;
  818.     unsigned long                    tcpDupPkts;
  819.     unsigned long                    tcpRetransPkts;
  820. };
  821. typedef struct TCPStats TCPStats;
  822.  
  823. typedef StreamPtr *StreamPPtr;
  824.  
  825. struct TCPGlobalInfoPB {
  826.     struct TCPParam                    *tcpParamPtr;
  827.     struct TCPStats                    *tcpStatsPtr;
  828.     StreamPPtr                        tcpCDBTable[1];
  829.     Ptr                                userDataPtr;
  830.     unsigned short                    maxTCPConnections;
  831. };
  832. typedef struct TCPGlobalInfoPB TCPGlobalInfoPB;
  833.  
  834. typedef void (*TCPIOCompletionProcPtr)(struct TCPiopb *iopb);
  835.  
  836. #if GENERATINGCFM
  837. typedef UniversalProcPtr TCPIOCompletionUPP;
  838. #else
  839. typedef TCPIOCompletionProcPtr TCPIOCompletionUPP;
  840. #endif
  841.  
  842. struct TCPiopb {
  843.     char                            fill12[12];
  844.     TCPIOCompletionUPP                ioCompletion;
  845.     short                            ioResult;
  846.     char                            *ioNamePtr;
  847.     short                            ioVRefNum;
  848.     short                            ioCRefNum;
  849.     short                            csCode;
  850.     StreamPtr                        tcpStream;
  851.         union {
  852.             struct TCPCreatePB                create;
  853.             struct TCPOpenPB                open;
  854.             struct TCPSendPB                send;
  855.             struct TCPReceivePB                receive;
  856.             struct TCPClosePB                close;
  857.             struct TCPAbortPB                abort;
  858.             struct TCPStatusPB                status;
  859.             struct TCPGlobalInfoPB            globalInfo;
  860.         }                            csParam;
  861. };
  862. typedef struct TCPiopb TCPiopb;
  863.  
  864.  
  865. #if GENERATINGCFM
  866. #else
  867. #endif
  868.  
  869. enum {
  870.     uppTCPIOCompletionProcInfo = kCStackBased
  871.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct TCPiopb*)))
  872. };
  873.  
  874. #if GENERATINGCFM
  875. #define NewTCPIOCompletionProc(userRoutine)        \
  876.         (TCPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppTCPIOCompletionProcInfo, GetCurrentArchitecture())
  877. #else
  878. #define NewTCPIOCompletionProc(userRoutine)        \
  879.         ((TCPIOCompletionUPP) (userRoutine))
  880. #endif
  881.  
  882. #if GENERATINGCFM
  883. #define CallTCPIOCompletionProc(userRoutine, iopb)        \
  884.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppTCPIOCompletionProcInfo, (iopb))
  885. #else
  886. #define CallTCPIOCompletionProc(userRoutine, iopb)        \
  887.         (*(userRoutine))((iopb))
  888. #endif
  889.  
  890.  
  891. enum {
  892.     UDPCreate                    = 20,
  893.     UDPRead                        = 21,
  894.     UDPBfrReturn                = 22,
  895.     UDPWrite                    = 23,
  896.     UDPRelease                    = 24,
  897.     UDPMaxMTUSize                = 25,
  898.     UDPStatus                    = 26,
  899.     UDPMultiCreate                = 27,
  900.     UDPMultiSend                = 28,
  901.     UDPMultiRead                = 29,
  902.     UDPCtlMax                    = 29
  903. };
  904.  
  905. enum {
  906.     UDPDataArrival                = 1,
  907.     UDPICMPReceived                = 2
  908. };
  909.  
  910. typedef unsigned short UDPEventCode;
  911.  
  912. typedef pascal void (*UDPNotifyProcPtr)(StreamPtr udpStream, unsigned short eventCode, Ptr userDataPtr, struct ICMPReport *icmpMsg);
  913.  
  914. #if GENERATINGCFM
  915. typedef UniversalProcPtr UDPNotifyUPP;
  916. #else
  917. typedef UDPNotifyProcPtr UDPNotifyUPP;
  918. #endif
  919.  
  920. enum {
  921.     uppUDPNotifyProcInfo = kPascalStackBased
  922.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(StreamPtr)))
  923.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned short)))
  924.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Ptr)))
  925.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(struct ICMPReport*)))
  926. };
  927.  
  928. #if GENERATINGCFM
  929. #define NewUDPNotifyProc(userRoutine)        \
  930.         (UDPNotifyUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppUDPNotifyProcInfo, GetCurrentArchitecture())
  931. #else
  932. #define NewUDPNotifyProc(userRoutine)        \
  933.         ((UDPNotifyUPP) (userRoutine))
  934. #endif
  935.  
  936. #if GENERATINGCFM
  937. #define CallUDPNotifyProc(userRoutine, udpStream, eventCode, userDataPtr, icmpMsg)        \
  938.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppUDPNotifyProcInfo, (udpStream), (eventCode), (userDataPtr), (icmpMsg))
  939. #else
  940. #define CallUDPNotifyProc(userRoutine, udpStream, eventCode, userDataPtr, icmpMsg)        \
  941.         (*(userRoutine))((udpStream), (eventCode), (userDataPtr), (icmpMsg))
  942. #endif
  943.  
  944. typedef unsigned short udp_port;
  945.  
  946. /* for create and release calls */
  947. struct UDPCreatePB {
  948.     Ptr                                rcvBuff;
  949.     unsigned long                    rcvBuffLen;
  950.     UDPNotifyUPP                    notifyProc;
  951.     unsigned short                    localPort;
  952.     Ptr                                userDataPtr;
  953.     udp_port                        endingPort;
  954. };
  955. typedef struct UDPCreatePB UDPCreatePB;
  956.  
  957. struct UDPSendPB {
  958.     unsigned short                    reserved;
  959.     ip_addr                            remoteHost;
  960.     udp_port                        remotePort;
  961.     Ptr                                wdsPtr;
  962.     Boolean                            checkSum;
  963.     UInt8                            filler;                        /* Filler for proper byte alignment     */
  964.     unsigned short                    sendLength;
  965.     Ptr                                userDataPtr;
  966.     udp_port                        localPort;
  967. };
  968. typedef struct UDPSendPB UDPSendPB;
  969.  
  970. /* for receive and buffer return calls */
  971. struct UDPReceivePB {
  972.     unsigned short                    timeOut;
  973.     ip_addr                            remoteHost;
  974.     udp_port                        remotePort;
  975.     Ptr                                rcvBuff;
  976.     unsigned short                    rcvBuffLen;
  977.     unsigned short                    secondTimeStamp;
  978.     Ptr                                userDataPtr;
  979.     ip_addr                            destHost;                    /* only for use with multi rcv */
  980.     udp_port                        destPort;                    /* only for use with multi rcv */
  981. };
  982. typedef struct UDPReceivePB UDPReceivePB;
  983.  
  984. struct UDPMTUPB {
  985.     unsigned short                    mtuSize;
  986.     ip_addr                            remoteHost;
  987.     Ptr                                userDataPtr;
  988. };
  989.  
  990. typedef struct UDPMTUPB UDPMTUPB;
  991.  
  992.                                         // •• ES bug fix: completed UPP for completion proc
  993.                                         
  994. typedef void (*UDPIOCompletionProcPtr)(struct UDPiopb *iopb);
  995.  
  996. #if GENERATINGCFM
  997. typedef UniversalProcPtr UDPIOCompletionUPP;
  998. #else
  999. typedef UDPIOCompletionProcPtr UDPIOCompletionUPP;
  1000. #endif
  1001.  
  1002. enum {
  1003.     uppUDPIOCompletionInfo = kCStackBased
  1004.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct UDPiopb*)))
  1005. };
  1006.  
  1007. #if GENERATINGCFM
  1008. #define NewUDPIOCompletionProc(userRoutine)        \
  1009.         (UDPIOCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppUDPIOCompletionInfo, GetCurrentArchitecture())
  1010. #else
  1011. #define NewUDPIOCompletionProc(userRoutine)        \
  1012.         ((UDPIOCompletionUPP) (userRoutine))
  1013. #endif
  1014.  
  1015. #if GENERATINGCFM
  1016. #define CallUDPIOCompletionProc(userRoutine, udpStream, eventCode, userDataPtr, icmpMsg)        \
  1017.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppUDPIOCompletionInfo, (udpStream), (eventCode), (userDataPtr), (icmpMsg))
  1018. #else
  1019. #define CallUDPIOCompletionProc(userRoutine, udpStream, eventCode, userDataPtr, icmpMsg)        \
  1020.         (*(userRoutine))((udpStream), (eventCode), (userDataPtr), (icmpMsg))
  1021. #endif
  1022.  
  1023. struct UDPiopb {
  1024.     char                            fill12[12];
  1025.     UDPIOCompletionUPP                ioCompletion;
  1026.     short                            ioResult;
  1027.     char                            *ioNamePtr;
  1028.     short                            ioVRefNum;
  1029.     short                            ioCRefNum;
  1030.     short                            csCode;
  1031.     StreamPtr                        udpStream;
  1032.         union {
  1033.             struct UDPCreatePB                create;
  1034.             struct UDPSendPB                send;
  1035.             struct UDPReceivePB                receive;
  1036.             struct UDPMTUPB                    mtu;
  1037.         }                            csParam;
  1038. };
  1039. typedef struct UDPiopb UDPiopb;
  1040.  
  1041.  
  1042. #ifdef __CFM68K__
  1043. #pragma lib_export off
  1044. #endif
  1045.  
  1046. #if GENERATINGPOWERPC
  1047. #pragma options align=reset
  1048. #endif
  1049.  
  1050. #ifdef __cplusplus
  1051. }
  1052. #endif
  1053.  
  1054. #endif /* __MACTCP__ */
  1055.